#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	return (a%b==0? b : gcd(b, a%b));
}
struct fenshu{
	ll x,y;
	fenshu operator + (const fenshu& a) {
		fenshu res;
		res.x=x*a.y+a.x*y;
		res.y=a.y*y;
		ll gg=gcd(res.x, res.y);
		res.x/=gg; res.y/=gg;
		return res;
	}
	fenshu operator / (const ll& a) {
		fenshu res;
		res.x=x; res.y=y*a;
		ll gg=gcd(res.x, res.y);
		res.x/=gg; res.y/=gg;
		return res;
	}
	bool operator == (const fenshu& a) {
		return x==a.x&&y==a.y;
	}
	bool operator < (const fenshu& a) const  {
		return x*a.y < a.x*y;
	}
	bool operator > (const fenshu& a) const {
		return x*a.y > a.x*y;
	}
	void print() {
		cout<<x<<"/"<<y;
	}
};
fenshu a[107][107], now[107][107];
ll n,m,t;
void show() {
	for (ll i=0; i<n; ++i) {
		for (ll j=0; j<m; ++j) a[i][j].print(), cout<<" ";
		cout<<endl;
	}
}
ll MOD(ll a, ll b) {
	ll res=a%b;
	if (res<0) res+=b;
	return res;
}
int main() {
	int tmp;
	while (cin>>m>>n>>t) {
		for (ll i=0; i<n; ++i) {
			for (ll j=0; j<m; ++j) {
				scanf("%d", &tmp);
				if (tmp==0) a[i][j].x=0, a[i][j].y=1;
				else a[i][j].x=1, a[i][j].y=1;
			}
		}
		while (t--) {
			for (ll i=0; i<n; ++i) {
				for (ll j=0; j<m; ++j) {
					fenshu mdzz;
					mdzz.x=0, mdzz.y=1;
					for (ll k=-1; k<2; ++k) {
						for (ll l=-1; l<2; ++l) {
							mdzz=mdzz+a[MOD(i+k,n)][MOD(j+l,m)];
						}
					}
					mdzz=mdzz/9;
					now[i][j]=mdzz;
				}
			}
			for (ll i=0; i<n; ++i) {
				for (ll j=0; j<m; ++j) {
					a[i][j]=now[i][j];
				}
			}		
		}
//		show();
		set<fenshu> s;
		for (ll i=0; i<n; ++i) 
			for (ll j=0; j<m; ++j) {
				s.insert(a[i][j]);
			}
		cout<<s.size()<<endl; 
	}
	return 0;
}
